// Storage相关
function getStore (name1, name2) {
  if (!name1) return false;
  let baseStore = wx.getStorageSync(name1);
  if (!baseStore) return false;
  return name2 ? (baseStore[name2] || '') : baseStore;
}
function setStore (name, value) {
  if (!name) return false;
  return wx.setStorageSync(name, value);
}
function setStoreChild (name1, name2, value) {
  if (!name1 || !name2) return false;
  let baseStore = getStore(name1) || {};
  baseStore[name2] = value;
  return setStore(name1, baseStore);
}
/**
 * 获取数据类型
 * @param value
 * @returns {*}
 */
function getValueType(value) {
  if (typeof value === 'number') return Number;
  if (typeof value === 'string') return String;
  if (typeof value === 'boolean') return Boolean;

  if (value instanceof Object && !value instanceof Array) return Object;
  if (value instanceof Array) return Array;

  return null;
}
/**
 * 获取当前页面上下文
 * @returns {*}
 */
function getPageContext() {
  var pages = getCurrentPages();
  return pages[pages.length - 1];
}
/**
 * 获取元素
 * @param classItem
 */
function $select(className, cb) {
  const query = wx.createSelectorQuery().in(this)
  query.select(className).boundingClientRect()
  query.selectViewport().scrollOffset()
  query.exec(function (res) {
    cb(className.substr('0') === '#' ? res[0] : res);
  })
}

module.exports = {
  getStore,
  setStore,
  setStoreChild,
  getValueType,
  getPageContext,
  $select
}